import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
	
]
// 动态路由
export const asyncRoutes = [
	{
	  path: '/project',
	  component: Layout,
		permission: "project",
		meta: {},
	  children: [{
	    path: 'list',
	    name: '工程项目库',
	    component: () => import('@/views/project/index'),
	    meta: { title: '工程项目库', icon: 'el-icon-s-cooperation' }
	  }]
	},
	{
	  path: '/survey/l',
	  component: Layout,
		permission: "surveyList",
		meta: {},
	  children: [{
	    path: 'list',
	    name: '勘察记录',
	    component: () => import('@/views/survey/list/index'),
	    meta: { title: '勘察记录', icon: 'el-icon-pie-chart' }
	  }]
	},
	{
	  path: '/survey/p',
	  component: Layout,
		permission: "surveyProcess",
		meta: {},
	  children: [{
	    path: 'process',
	    name: '勘察记录审核',
	    component: () => import('@/views/survey/process/index'),
	    meta: { title: '勘察记录审核', icon: 'el-icon-search' }
	  }]
	},
	{
	  path: '/scheme/l',
	  component: Layout,
		permission: "schemeList",
		meta: {},
	  children: [{
	    path: 'list',
	    name: '施工方案',
	    component: () => import('@/views/scheme/list/index'),
	    meta: { title: '施工方案', icon: 'el-icon-folder-remove' }
	  }]
	},
	{
	  path: '/scheme/p',
	  component: Layout,
		permission: "schemeProcess",
		meta: {},
	  children: [{
	    path: 'process',
	    name: '施工方案审核',
	    component: () => import('@/views/scheme/process/index'),
	    meta: { title: '施工方案审核', icon: 'el-icon-bank-card' }
	  }]
	},
	{
	  path: '/jobTicket/l',
	  component: Layout,
		permission: "jobTicketList",
		meta: {},
	  children: [{
	    path: 'list',
	    name: '交底单',
	    component: () => import('@/views/jobTicket/list/index'),
	    meta: { title: '交底单', icon: 'el-icon-document-remove' }
	  }]
	},
	// {
	//   path: '/jobTicket/p',
	//   component: Layout,
	// 	permission: "jobTicketProcess",
	// 	meta: {},
	//   children: [{
	//     path: 'process',
	//     name: '交底单审核',
	//     component: () => import('@/views/jobTicket/process/index'),
	//     meta: { title: '交底单审核', icon: 'el-icon-tickets' }
	//   }]
	// },
	{
	  path: '/video',
	  component: Layout,
		permission: "videoSupervision",
		meta: {},
	  children: [{
	    path: 'list',
	    name: '视频督察',
	    component: () => import('@/views/video/playBack/index'),
	    meta: { title: '视频督察', icon: 'el-icon-video-camera' }
	  }]
	},
	{
	  path: '/setting',
		name: '人员权限管理',
		permission: "userDepartment",
		meta: {},
	  component: Layout,
		// alwaysShow: true,
		// meta: {
		//   title: '人员权限管理',
		//   icon: 'el-icon-setting'
		// },
	  children: [
			{
				path: 'user',
				name: '人员部门管理',
				component: () => import('@/views/setting/user/index'),
				meta: { title: '人员部门管理', icon: 'el-icon-setting' }
			}
		]
	}
  // {
  //   path: '/test',
  //   component: Layout,
  //   redirect: '/test/page1',
  //   permission: "/test",
  //   name: '动态路由',
  //   alwaysShow: true,
  //   meta: {
  //     title: '动态路由',
  //     icon: 'el-icon-s-help'
  //   },
  //   children: [
  //     {
  //       path: 'page1',
  //       component: () => import('@/views/test/page1'),
  //       name: '页面1',
  //       permission: "page1",
  //       meta: {
  //         title: '页面1'
  //       }
  //     },
  //     {
  //       path: 'page2',
  //       component: () => import('@/views/test/page2'),
  //       name: '页面2',
  //       permission: "page2",
  //       meta: {
  //         title: '页面2'
  //       }
  //     },
  //     {
  //       path: 'page3',
  //       component: () => import('@/views/test/page3'),
  //       name: '页面3',
  //       permission: "page3",
  //       meta: {
  //         title: '页面3'
  //       }
  //     }
  //   ]
  // }
]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
